<?php
class Teacher
{
	private $id;
	private $name;
	private $profession;

           /**
            * 一个教师教授多门课程
            *
            * @var Course
            */
	private $courses = [];

	public function __construct($id, $name, $profession)
	{
		$this->id = $id;
		$this->name = $name;
		$this->profession = $profession;
	}

	public function addCourse(Course $course)
	{
		$course->teacher = $this;
		$this->courses[] = $course;
	}

	public function introduce()
	{
		echo '我是' . $this->name . '，我负责的课程是：<br/>';
		foreach ($this->courses as $course) {
			echo $course->name . '&nbsp;&nbsp;';
		}
	}

	public function __get($name)
	{
		if(property_exists(self::class, $name)) {
			return $this->$name;
		}
		return null;
	}

	public function __set($name, $value)
	{
		if (property_exists(self::class, $name)) {
			$this->$name = $value;
		}
	}

	public function __tostring()
	{
		return 'id: ' . $this->id . ' 课程: ' . $this->name . ' 专业: ' . $this->profession . '<br/>'; 
	}
}